<%@ page import="com.interfaces.SendAgentController" %>
<%@ page import="java.util.Random" %>
<%@ page import="com.core.sysDict.SysDictJsp" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>送签社信息管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

    <%
    	String path = request.getContextPath();
            path = "/".equals(path)?"":path;
            request.setAttribute("path", path);
            String sysDictJson=SysDictJsp.getSysDictJson(session);
    %>
    <script type="text/javascript">
        var path = "${path}";
    </script>

    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="${path}/public/adminlte/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="${path}/public/font-awesome-4.7.0/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="${path}/public/ionicons/ionicons.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="${path}/public/adminlte/plugins/datatables/dataTables.bootstrap.css">

    <!-- Theme style -->
    <link rel="stylesheet" href="${path}/public/adminlte/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. We have chosen the skin-blue for this starter
          page. However, you can choose any other skin. Make sure you
          apply the skin class to the body tag so the changes take effect.
    -->
    <link rel="stylesheet" href="${path}/public/adminlte/dist/css/skins/_all-skins.min.css">

    <link rel="stylesheet" href="${path}/css/common.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<!--
BODY TAG OPTIONS:
=================
Apply one or more of the following classes to get the
desired effect
|---------------------------------------------------------|
| SKINS         | skin-blue                               |
|               | skin-black                              |
|               | skin-purple                             |
|               | skin-yellow                             |
|               | skin-red                                |
|               | skin-green                              |
|---------------------------------------------------------|
|LAYOUT OPTIONS | fixed                                   |
|               | layout-boxed                            |
|               | layout-top-nav                          |
|               | sidebar-collapse                        |
|               | sidebar-mini                            |
|---------------------------------------------------------|
-->
<body >
<div class="container">

            <div class="box box-primary">
                <!-- /.box-header -->
                <div class="box-body">
                    <div class="row">
                        <div class="col-md-3">
                            <div class="form-group">
                                <label for="sendAgentName">送签社名称</label>
                                <input type="text" class="form-control" id="sendAgentName">
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-12 text-right">
                            <button type="submit" id="btnSearch" class="btn btn-primary">搜 索</button>
                            <button class="btn btn-primary" onclick="btnDel()">删 除</button>
                            <button type="submit" id="btnAdd" class="btn btn-primary">新增送签社</button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.box -->
            <div class="box box-primary">
                <!-- /.box-header -->
                <div class="box-body">
                    <table id="dg" class="table table-bordered table-hover">
                    </table>
                </div>
                <!-- /.box-body -->
            </div>
</div>

<!-- ./wrapper -->

<div class="modal fade" id="modelContainer" role="basic" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        </div>
    </div>
</div>

<!-- REQUIRED JS SCRIPTS -->

<!-- jQuery 2.2.3 -->
<script src="${path}/public/adminlte/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="${path}/public/adminlte/bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="${path}/public/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${path}/public/adminlte/plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="${path}/public/adminlte/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="${path}/public/adminlte/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="${path}/public/adminlte/dist/js/app.min.js"></script>
<!-- 字典-->
<script src="${path}/js/sysDict.js"></script>
<!-- Optionally, you can add Slimscroll and FastClick plugins.
     Both of these plugins are recommended to enhance the
     user experience. Slimscroll is required when using the
     fixed layout. -->
<!-- page script -->
<script>
	var table;
	var url = window.location.search;
	var arr=url.split('&');
	var curid = "tab_"+arr[arr.length-2];
	console.info(curid);
	var sysDict='<%=sysDictJson%>';
	var re = JSON.parse(sysDict);
	window.onload=function(){
    init();
    $("#checkAll").click(function () {
      var check = $(this).prop("checked");
      $(".checkchild").prop("checked", check);
		});	
    };
	function init() {
    	
        table=$('#dg').DataTable({
            "iDisplayLength" : 10,
            "paging": true,
            "lengthChange": true,
            "bSort" : false,
            "processing" : true,
            "serverSide" : true,
            "searching": false,
            "ordering": false,
            "autoWidth": false,
            "ajax":{
            	 "url":"${path}<%=SendAgentController.URL_DB_SEARCH%>?&"+arr[arr.length-1],
            	 "type":"post",
            },
            "columns":[
            		{
            		"data":"id",
            		"title":"<input type='checkbox' class='check' id='checkAll'>",
            		"defaultContent":"",
            		"render":function(data, type, full, meta){
            			return '<input type="checkbox" name="subcheck" class="checkchild"  value="' + data + '" />';
            			},
            			"bSortable": false
            		},
            		{ "data": "id",
            		  "title":"送签社id",
            		  "render":function(data, type, full, meta){
            		  	return'<A href="javascript:updateFund(&quot;'+data+'&quot;);">'+ data +'</A>';
            			},
            		 },
             		{ "data": "sendAgentName","title":"送签社名称","defaultContent":"" },
             		{ "data": "code","title":"送签社代码","defaultContent":""},
             		{ "data": "sendAgentField", "title":"送签社归属领区","defaultContent":""} 
            ],
            "language": {
                "sProcessing": "处理中...",
                "sLengthMenu": "显示 _MENU_ 项结果",
                "sZeroRecords": "没有匹配结果",
                "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix": "",
                "sSearch": "搜索:",
                "sUrl": "",
                "sEmptyTable": "表中数据为空",
                "sLoadingRecords": "载入中...",
                "sInfoThousands": ",",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上页",
                    "sNext": "下页",
                    "sLast": "末页"
                },
                "oAria": {
                    "sSortAscending": ": 以升序排列此列",
                    "sSortDescending": ": 以降序排列此列"
                }
            }
        });
    }
        $("#btnAdd").click(function () {
               	var CustodianID=new Date().getTime()+''+Math.floor(Math.random() * 8998 + 1000);
               	parent.addTab({title: "新增送签社机构信息", url:"${path}<%=SendAgentController.URL_GOTO_ADD_UPDATE_PAGE%>?&"+CustodianID+"&"+curid, id: CustodianID, close: true, single:true,act:1});
        });
        $("#btnSearch").click(function(){
       		var param = {
		        "sendAgentName": $('#sendAgentName').val(),
	    	};
	    	table.settings()[0].ajax.data = param;
       		table.ajax.reload();
        });   
    function btnDel(){  
               //判断至少写了一项  
               var checkedNum = $("input[name='subcheck']:checked").length;  
               if(checkedNum==0){  
                   alert("请至少选择一项!");  
                   return false;  
               }  
               if(confirm("确定删除所选项目?")){  
               var checkedList = new Array();  
               $("input[name='subcheck']:checked").each(function(){  
                   checkedList.push($(this).val());  
               });  
               $.ajax({  
                   type:"POST",  
                   url:"${path}<%=SendAgentController.URL_DELETE%>",  
                   data:{"delitems":checkedList.toString()},    
                   success:function(result){  
                   	   var re = JSON.parse(result);
                   	   if(re.returnCode=="0"){
                   	   		$("[name='checkbox2']:checkbox").attr("checked",false);  
                       		location.reload();
                   	   }else{
                   	   	alert(re.msg);
                   	   }
                   },  
           		   error:function(request) {      // 设置表单提交出错
                	alert(request);  //登录错误提示信息
            	   }
               });  
               }  
       } 
	   function updateFund(code){
   		 var CustodianID=new Date().getTime()+''+Math.floor(Math.random() * 8998 + 1000);
    	 parent.addTab({title: "修改送签社机构信息", url:"${path}<%=SendAgentController.URL_GOTO_UPDATE_PAGE%>?id="+code+"&"+CustodianID+"&"+curid, id: CustodianID, close: true, single:true});
    }   
     function freshOK(){
        console.info("success");
        table.draw( false );
        }; 
		
</script>
</body>
</html>